package com.functest.orm

/**
 * @author: DavydovMD
 * Date: 18.04.13
 * Time: 14:23
 *
 * Field references are mostly used in MapperBindings/MultiTableMappers when defining bindings between two tables
 */

class FieldReference {
    final String field = ''
    final Mapper mapper

    @Override
    String toString(){
        "FieldRef[${mapper.name}:${field}]"
    }

    FieldReference(Mapper mapper, String fieldName) {
        this.field = fieldName
        this.mapper = mapper
    }


    String getFqn() {
        mapper.getFqSourceName(field)
    }

    boolean equals(o) {
        if (this.is(o)) return true
        if (!(o instanceof FieldReference)) return false

        FieldReference that = (FieldReference) o

        if (field != that.field) return false
        if (mapper != that.mapper) return false

         true
    }

    int hashCode() {
        int result
        result = (field != null ? field.hashCode() : 0)
        result = 31 * result + (mapper != null ? mapper.hashCode() : 0)
        result
    }
}

